package twelfth.压缩流;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class 压缩文件 {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\WorkSpaces\\JavaDevelopBase_start_329\\src\\twelfth\\demo2.txt");
        File zipfile = new File("D:\\WorkSpaces\\JavaDevelopBase_start_329\\src\\twelfth\\demo2.zip");
        InputStream fis = new FileInputStream(file);
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipfile));
        zos.putNextEntry(new ZipEntry(file.getName()));
        zos.setComment("为了压缩一个文件");
        int temp = 0;
        while ((temp = fis.read()) != -1) {
            zos.write(temp);    //边读边写
        }
        fis.close();
        zos.close();
    }
}
